'use strict';
const Generator = require('yeoman-generator');
const chalk = require('chalk');
const yosay = require('yosay');
const path = require('path');
const _ = require('lodash');
const extend = require('deep-extend');
const mkdirp = require('mkdirp');


module.exports = class extends Generator {
  prompting() {
    // Have Yeoman greet the user.
    this.log(yosay(
      'Welcome to the groundbreaking ' + chalk.red('generator-nodjs-nutzcli') + ' generator!'
    ));

    const prompts = [{
      type: 'input',
      name: 'groupId',
      message: 'maven groupId,eg: cn.dav',
      default: 'cn.dav'
    },{
      type: 'input',
      name: 'artifactId',
      message: 'maven artifactId,eg: dav-parent',
      default: 'dav-parent'
    },{
      type: 'list',
      name: 'packaging',
      message: '请选择 packaging 类型:',
      choices: ['jar', 'war', 'pom', 'ejb','ear','rar','par','maven-plugin']
    },{
      type: 'input',
      name: 'version',
      message: 'maven version,eg: 1.0-SNAPSHOT',
      default: '1.0-SNAPSHOT'
    },{
      type: 'confirm',
      name: 'someAnswer',
      message: 'Would you like to enable this option?',
      default: true
    }];

    return this.prompt(prompts).then(props => {
      // To access props later use this.props.someAnswer;
      this.args = props;
      this.props = props;
    });
  }

  writing() {

   // const grpid = this.args.groupId.split(".");
    console.log(this.args);

    const cpyt = [
      "pom.xml", "README.md"
    ];

    for (var i in cpyt) {
      this.fs.copyTpl(
        this.templatePath(cpyt[i]),
        this.destinationPath(cpyt[i]), {
          artifactId: this.args.artifactId,
          groupId: this.args.groupId,
          version: this.args.version,
          packaging: this.args.packaging,
        });
    }
  }

  install() {

  }

  end() {
    this.config.save();
  }
};
